Like   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Function

Rating   Name   Duplication   Size   Complexity  
A run 0 21 4
1
import Tweet from '../entities/Tweet';
2 3
import {AbstractAction, runArgs} from './Action';
3 3
import Helper from '../Helper';
4
5
interface runLikeArgs extends runArgs {
6
    tweet: Tweet
7
}
8
9 3
export default class Like extends AbstractAction {
10
    async run(args: runLikeArgs): Promise<void> {
11 5
        const {tweet, onSuccess} = args;
12
13 5
        this.debug(`Liking tweet with id: '${tweet.rawTweet.id_str}' ...`);
14 5
        const result = await this.twit.post('favorites/create', {
15
            id: tweet.rawTweet.id_str
16
        });
17
18 4
        if (this.isSuccessResponse(result)) {
19 2
            this.debug('Liked!');
20
21 2
            if (onSuccess) {
22 1
                await onSuccess(tweet);
23
            }
24
        } else {
25 2
            this.debug('Cannot like.');
26 2
            if (Helper.objectExists(result.resp.statusMessage)) {
27 1
                this.debug(result.resp.statusMessage);
28
            }
29
30 2
            throw new Error('Cannot like');
31
        }
32
    }
33
}